package com.atguigu.distributed.lock.leecode;

/**
 * 求两数的最大公约数
 */
public class GreatestCommonDivisor {
    public static int getGreatestCommonDivisorV2(int a,int b){
        int big = a>b?a:b;
        int small = a<b?a:b;
        if(big%small==0){
            return small;
        }
        return getGreatestCommonDivisorV2(big%small, small);
    }
    public static int getGreatestCommonDivisorV3(int a,int b) {
        if(a==b){
            return a;
        }
        int big = a > b ? a : b;
        int small = a < b ? a : b;

        return getGreatestCommonDivisorV3(big-small,small);
    }

    public static void main(String[] args) {
        int greatestCommonDivisorV2 = getGreatestCommonDivisorV3(81, 63);
        System.out.println(greatestCommonDivisorV2);
    }
}
